package com.kerrykidz.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.kerrykidz.membership.dao.model.CusMemEntity;
import com.kerrykidz.membership.dao.model.CusMemSalesEntity;
import com.kerrykidz.system.dao.model.SecUsrEntity;
import com.kerrykidz.system.service.ICusMemService;
import com.kerrykidz.system.service.IUserService;
import com.rdp.framework.exception.RDPException;

@RequestMapping("SalesRelation")
@Controller
public class CusMemController {
	@Autowired
	private ICusMemService iCusMemService;
	@Autowired
	private IUserService userService;
	@RequestMapping("/mem")
	public ModelAndView mem(){
		List<SecUsrEntity> listuserPar =userService.listUserByRoleId("106");
		ModelAndView mv = new ModelAndView("system/system_gual");
		mv.addObject("listuserPar", listuserPar);
		return mv;
	}
	
	@RequestMapping("/sales")
	@ResponseBody
	public CusMemEntity findSaleDetail(CusMemEntity entity)throws RDPException{
		
		return iCusMemService.findBySalesName(entity);
		
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public String UpdateMemSales(CusMemSalesEntity entity)throws RDPException{
		iCusMemService.updateSalesByMemberId(entity);
		return"success";
	}
	
	@RequestMapping("/updateBatch")
	@ResponseBody
	public String updateBatch(String id,CusMemSalesEntity entity)throws RDPException{
		String [] memId = id.split(",");
		int length = memId.length;
		for(int i=0;i<length;i++){
			entity.setFkMemId(memId[i]);
			iCusMemService.updateSalesByMemberId(entity);
		}
		return"success";
	}
}
